package com.baboba.rummy.web.client.game;

import com.baboba.rummy.game.GameEventHandler;
import com.baboba.rummy.game.GameManager;
import com.baboba.rummy.player.Player;
import com.baboba.rummy.web.client.arena.ArenaView;
import com.baboba.rummy.web.client.player.HumanPlayerView;
import com.baboba.rummy.web.client.player.PlayerView.Direction;
import com.baboba.rummy.web.client.player.RobotPlayerView;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.Widget;

public class GameView extends Composite implements GameEventHandler{
	
	private DockLayoutPanel topPanel;
	private DockLayoutPanel playPanel;
	private ArenaView arenaView;

	public GameView(){
		topPanel = new DockLayoutPanel(Unit.PX);
		
		topPanel.addNorth(new ActionToolbar(), 80);
		topPanel.add(createPlayPanel());
		
		GameManager.getInstance().addEventHandler(this);
		this.initWidget(topPanel);
	}

	private Widget createPlayPanel() {
		playPanel = new DockLayoutPanel(Unit.PX);
		
		
		return playPanel;
	}

	@Override
	public void onCreateNewGame() {
		Player[] players = GameManager.getInstance().getPlayers();
		
		RobotPlayerView playerView = new RobotPlayerView(players[0], Direction.Horizontal);
		HumanPlayerView humanPlayerView = new HumanPlayerView(players[1], Direction.Horizontal);
		arenaView = new ArenaView();
		
		playPanel.clear();
		playPanel.addNorth(playerView, 80);
		playPanel.addSouth(humanPlayerView, 80);
		playPanel.add(arenaView);
	}

	@Override
	public void onCreateNewRound() {
		arenaView.redrawArenaPanel();
	}

	
}
